package com.kyzh.core.pager.weal.community.viewmodel

import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.gushenge.core.beans.*
import com.gushenge.core.requests.weal.CommunityRequest
import kotlinx.coroutines.launch

class CommunityViewModel : ViewModel() {


        //$type=0 社区列表，$type=1 社区内的全部社区   $type=2 社区内的我的关注
     fun getData(p:Int,type :Int,key :String = "",listener: CommunityListBean.()->Unit){
        viewModelScope.launch {
            CommunityRequest.getData(p,type,key, listener)
        }
    }
    // 关注
    fun guanzhu(id:String,listener:  ()->Unit){
        viewModelScope.launch {
            CommunityRequest.guanzhu(id, listener)
        }
    }
    // 游戏社区顶部
    fun getCommunityTop(id:String,listener: CommunityBean.Data. ()->Unit){
        viewModelScope.launch {
            CommunityRequest.getCommunityTop(id, listener)
        }
    }
    // 游戏社区列表
    fun getCommunityNews(p:Int,id:String,type:Int,listener:  FragCommunityBean . ()->Unit){
        viewModelScope.launch {
            CommunityRequest.getCommunityNews(p, id, type, listener)
        }
    }
    // 删除
    fun newsDel(id:String,listener:()->Unit){
        viewModelScope.launch {
            CommunityRequest.newsDel(id, listener)
        }
    }

    // 新闻详情
    fun getNewsDetail(id:String?,listener:FragCommunityBean.Data?.()->Unit){
        viewModelScope.launch {
            CommunityRequest.getNewsDetail(id, listener)
        }
    }
    // 评论列表
    fun getPingLunList(p:Int,id:String?, listener: CommunityPingLunBean.()->Unit){
        viewModelScope.launch {
            CommunityRequest.getPingLunList(p, id, listener)
        }
    }
    /**
     * @param type Int 	分类 2攻略 4问题
     * @param pid String 社区ID
     * @param title String
     * @param content String
     * @param image ArrayList<String>
     */
    fun subPingLun (type: Int,pid:String ,title:String ,content:String , image:String,listener: Code<String>.() -> Unit){
        viewModelScope.launch {
            CommunityRequest.subPingLun(type, pid, title, content, image, listener)
        }
    }

    /**
     *
     * @param type Int 0 对文章点赞  1 对评论点赞
     * @param pid String 文章或评论的id
     * @param puid String 上级的uid 文章或者评论的发布者
     */
    fun zan (type:Int, pid:String,puid:String,listener: Int.() -> Unit){
        viewModelScope.launch {
            CommunityRequest.zan(type, pid, puid, listener)
        }
    }

    /**
     * @param type:String  1 对评论   0 对文章
     * @param content String
     * @param pid String  文章id 或者评论id (主评论) 子评论也传主评论id
     * @param puid String  文章id 或者评论uid 如果是回复子评论咋传子评论uid
     * @param listener [@kotlin.ExtensionFunctionType] Function1<Int, Unit>
     */
    fun huifu (type:String,content:String, pid:String,puid:String,listener: Int.() -> Unit){
        viewModelScope.launch {
            CommunityRequest. huifu(type, content, pid, puid, listener)
        }
    }
    // 我的回复
    fun wodehuifu(p:Int,listener:CommunityPingLunBean.() -> Unit){
        viewModelScope.launch {
            CommunityRequest.wodehuifu(p, listener)
        }
    }
    //我的消息
    fun meNews(p:Int,listener: FragCommunityBean.() -> Unit){
        viewModelScope.launch {
            CommunityRequest.meNews(p, listener)
        }
    }

}